package demo.pattern.proxy.jdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @ClassName jdkDaynamicProxyUtil
 * @Description
 * @Author 47980
 * @Date 2020/8/9 15:48
 * @Version V_1.0
 **/
public class JdkDynamicProxyUtil {

    public static <T>T newProxyInstance(T targetObjcet, InvocationHandler handler) {
        ClassLoader classLoader = targetObjcet.getClass().getClassLoader();
        Class<?>[] interfaces = targetObjcet.getClass().getInterfaces();
        return (T) Proxy.newProxyInstance(classLoader, interfaces, handler);
    }
}
